{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您已成年，可以进入！\n"
     ]
    }
   ],
   "source": [
    "# 示例：年龄验证\n",
    "age = 20\n",
    "if age >= 18:\n",
    "    print(\"您已成年，可以进入！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "您已经成年！\n"
     ]
    }
   ],
   "source": [
    "age = 18\n",
    "if age >= 18:\n",
    "    print(\"您已经成年！\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "15.0 是奇数\n"
     ]
    }
   ],
   "source": [
    "# 示例：奇偶判断\n",
    "num = 15.00\n",
    "if num % 2 == 0:\n",
    "    print(num, \"是偶数\")\n",
    "else:\n",
    "    print(num, \"是奇数\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "B\n"
     ]
    }
   ],
   "source": [
    "# 示例：成绩等级评定\n",
    "score = 85\n",
    "if score >= 90:\n",
    "    print(\"A\")\n",
    "elif 80 <= score < 90:\n",
    "    print(\"B\")\n",
    "elif 70 <= score < 80:\n",
    "    print(\"C\")\n",
    "else:\n",
    "    print(\"D\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "密码错误\n"
     ]
    }
   ],
   "source": [
    "# 嵌套示例：用户登录验证\n",
    "username = \"admin\"\n",
    "password = \"12345678\"\n",
    "\n",
    "if username == \"admin\":\n",
    "    if password == \"123456\":\n",
    "        print(\"登录成功！\")\n",
    "    else:\n",
    "        print(\"密码错误\")\n",
    "else:\n",
    "    print(\"用户名不存在\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 示例：返回较大值\n",
    "a, b = 10, 20\n",
    "max_value = a if a > b else b\n",
    "print(max_value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 10\n",
    "b = 20\n",
    "if a > b:\n",
    "    max_value = a\n",
    "else:\n",
    "    max_value = b\n",
    "print(max_value)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "a = 10\n",
    "b = 20\n",
    "c = 30\n",
    "a, b, c = 10, 20, 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
   "source": [
    "# 短路运算示例\n",
    "lst = \"\"\n",
    "check_list = len(lst) > 0 and lst == \"Python\"\n",
    "\n",
    "# 当传入空列表时不会触发索引错误，因为len(lst) > 0为False导致直接返回False\n",
    "print(check_list)  # 安全地返回False"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "for i in 图片迭代器：\n",
    "    i = 这个图片"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "49995000\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "for i in range(1, 10000):\n",
    "    sum += i # sum = sum + i\n",
    "\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24995000\n"
     ]
    }
   ],
   "source": [
    "sum = 0 \n",
    "for i in range(10000):\n",
    "    if i % 2 == 0:\n",
    "        sum += i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "24995000\n"
     ]
    }
   ],
   "source": [
    "sum = 0 \n",
    "for i in range(2, 10000, 2):\n",
    "    sum += i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "```C\n",
    "int sum = 0;\n",
    "for (int i = 0; i < 10000; i=i+2) {\n",
    "    sum += i;\n",
    "    }\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "99998\n"
     ]
    }
   ],
   "source": [
    "sum = 0 \n",
    "for i in range(2, 100000, 2):\n",
    "    sum += i\n",
    "    if sum > 10000:\n",
    "        break\n",
    "print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2499700500\n"
     ]
    }
   ],
   "source": [
    "sum = 0 \n",
    "for i in range(0, 100000, 2):\n",
    "    if i < 1000:\n",
    "        continue\n",
    "    else:\n",
    "        sum += i\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "49995000\n"
     ]
    }
   ],
   "source": [
    "sum = 0\n",
    "i = 0\n",
    "while i < 10000:\n",
    "    sum += i\n",
    "    i += 1\n",
    "print(sum)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "剩余尝试次数：2\n",
      "剩余尝试次数：1\n",
      "剩余尝试次数：0\n",
      "剩余尝试次数：-1\n",
      "剩余尝试次数：-2\n",
      "剩余尝试次数：-3\n",
      "剩余尝试次数：-4\n",
      "剩余尝试次数：-5\n",
      "剩余尝试次数：-6\n",
      "剩余尝试次数：-7\n",
      "剩余尝试次数：-8\n",
      "剩余尝试次数：-9\n",
      "剩余尝试次数：-10\n",
      "剩余尝试次数：-11\n",
      "剩余尝试次数：-12\n",
      "剩余尝试次数：-13\n",
      "剩余尝试次数：-14\n",
      "剩余尝试次数：-15\n",
      "剩余尝试次数：-16\n",
      "剩余尝试次数：-17\n",
      "剩余尝试次数：-18\n",
      "剩余尝试次数：-19\n",
      "剩余尝试次数：-20\n",
      "剩余尝试次数：-21\n",
      "剩余尝试次数：-22\n",
      "剩余尝试次数：-23\n",
      "剩余尝试次数：-24\n",
      "剩余尝试次数：-25\n",
      "剩余尝试次数：-26\n",
      "剩余尝试次数：-27\n",
      "剩余尝试次数：-28\n",
      "剩余尝试次数：-29\n",
      "剩余尝试次数：-30\n",
      "剩余尝试次数：-31\n",
      "剩余尝试次数：-32\n",
      "剩余尝试次数：-33\n",
      "剩余尝试次数：-34\n",
      "剩余尝试次数：-35\n",
      "剩余尝试次数：-36\n",
      "剩余尝试次数：-37\n",
      "剩余尝试次数：-38\n",
      "剩余尝试次数：-39\n",
      "剩余尝试次数：-40\n",
      "剩余尝试次数：-41\n",
      "剩余尝试次数：-42\n",
      "剩余尝试次数：-43\n",
      "剩余尝试次数：-44\n",
      "剩余尝试次数：-45\n",
      "验证成功！\n"
     ]
    }
   ],
   "source": [
    "# 密码重试机制\n",
    "max_attempts = 3\n",
    "attempt = 0\n",
    "\n",
    "while True:\n",
    "    password = input(\"请输入密码：\")\n",
    "    if password == \"deepseek\":\n",
    "        print(\"验证成功！\")\n",
    "        break\n",
    "    attempt += 1\n",
    "    print(f\"剩余尝试次数：{max_attempts - attempt}\")\n",
    "else:\n",
    "    print(\"账户已锁定，请联系管理员\")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
